function ConnectionLDAPMessageListener ()
{
}

ConnectionLDAPMessageListener.prototype.QueryInterface = function(iid)
{
	if (iid.equals(Components.interfaces.nsISupports) || iid.equals(Components.interfaces.nsILDAPMessageListener))
		return this;
	else
		Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
	return null;
}

ConnectionLDAPMessageListener.prototype.onLDAPInit = function(pConn, pStatus)
{
	jsdump("onLDAPInit called. LDAP initialization done.");

	var proxy = getProxyOnUIThread(new ConnectionLDAPMessageListener, Components.interfaces.nsILDAPMessageListener);

	var ldapOp = Components.classes["@mozilla.org/network/ldap-operation;1"].createInstance().QueryInterface(Components.interfaces.nsILDAPOperation);

	ldapOp.init(pConn, proxy, null);

	jsdump("Binding...");

	ldapOp.simpleBind("master");
}

ConnectionLDAPMessageListener.prototype.onLDAPMessage = function(pMsg)
{
	jsdump("ConnectionLDAPMessageListener: Message received");

	switch (pMsg.type)
	{
		case Components.interfaces.nsILDAPMessage.RES_BIND :
			jsdump("Bind result message received");
			var r = (pMsg.errorCode == Components.interfaces.nsILDAPErrors.SUCCESS);
			jsdump("(bind succeeded: "+r+")");
			break;
		default :
			jsdump("Message is not a bind result: we should not be here !!");
	}
}
